import React from "react";
import "./index.scss";
import { NavLink } from "react-router-dom";
class Center extends React.Component {
  // rendomColor() {
  //   this.r = Math.floor(Math.random() * 255);
  //   this.g = Math.floor(Math.random() * 255);
  //   this.b = Math.floor(Math.random() * 255);
  //   this.color = "rgba(" + this.r + "," + this.g + "," + this.b + ",0.8)";
  //   return this.color;
  // }

  render() {
    let userInfo = window.localStorage.getItem('userInfo')
    userInfo = JSON.parse(userInfo)
    
    return (
      <div>
        <div className="c_header">
          <div className="c_my">
            <div className="c_my_img" />
            {
              userInfo ? <span className="button">{userInfo.userName}</span> :
                (
                  <NavLink to='/login'>
                    <span className="button">立即登录</span>
                  </NavLink>
                )
            }
          </div>
        </div>
        <div className="member-center">
          <NavLink to='/money'>
            <div className="myqian">
              <img src="http://www.hangowa.com/wap/images/mc_02.png" alt="" />
              <span>我的钱包</span>
            </div>
          </NavLink>
          {
            userInfo ? (
              <div className="out_lngin">
                <button onClick={this.handleLogout}>退出登录</button>
              </div>
            ) : ''
          }
          
        </div>
      </div>
    )

  }
  handleLogout = () => {
    window.localStorage.removeItem('userInfo')
    // console.log(this.props)
    this.props.history.go('/login')
  }
}

export default Center;
